// 生成随机的唯一字符串
function createRandomWords(length: number = 15): string {
  const SEEDCHARS = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz';
  let maxPost = SEEDCHARS.length,
    random_string = '';
  if (length < 5) length = 5
  for (let i = length;i > 0;i--) {
    random_string += SEEDCHARS.charAt(Math.floor(Math.random() * maxPost))
  }
  if (length <= 10) {
    return random_string
  } else {
    return random_string.substr(0, length - 5) + (Date.now() + '').substr(8, 5)
  }
}

// 截取文件后面的后缀
function clipFileExts(filename: string, keepDot: boolean = false): string | boolean {
  let filenameArr = filename.split('.')
  if (filenameArr.length >= 2) {
    let ext = filenameArr[filenameArr.length - 1]
    return (keepDot ? '.' : '') + ext
  }
  return false
}

export {
  createRandomWords,
  clipFileExts
}

export default {
  createRandomWords,
  clipFileExts
}
